package org.itboys.shop.service.Manager;

import java.util.Map;
import java.util.stream.Collectors;

import org.itboys.commons.CommonConstants.NUM;
import org.itboys.commons.CommonConstants.StaticParam;
import org.itboys.commons.utils.tools.ImagePathUtils;
import org.itboys.member.service.MemberService;
import org.itboys.mongodb.utils.page.Page;
import org.itboys.product.service.ProductService;
import org.itboys.shop.dto.pro.WXShopDetailDto;
import org.itboys.shop.dto.pro.WXShopListDto;
import org.itboys.shop.entity.ShopSeller;
import org.itboys.shop.service.ShopSellerService;
import org.itboys.trade.dto.WXCommentListDto;
import org.itboys.trade.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Maps;

@Service
public class WXShopManager {
	@Autowired
	private ShopSellerService shopService;
	@Autowired
	private CommentService commentService;
	@Autowired
	private MemberService memberService;
	@Autowired
	private WXProManager proManager;
	@Autowired
	private ProductService proService;
	public  WXShopListDto getWXShopListDto(ShopSeller s) {
		return getWXShopListDto(s, null);
	}
	public  WXShopListDto getWXShopListDto(ShopSeller s,WXShopListDto dto) {
		if (null==dto) {
			dto = new WXShopListDto();
		}
		dto.setShopId(s.getId());
		dto.setImage(ImagePathUtils.add(StaticParam.imagePath, s.getMainImg()));
		dto.setName(s.getShopName());
		dto.setPrice(NUM.DF_00.format(shopService.getMinPrice(s.getId()) / 100d));
		dto.setAdvantageDesc(s.getAdvantageDesc());
		return dto;
	}
	public WXShopDetailDto getWXShopDetailDto(ShopSeller s){
		WXShopDetailDto dto=(WXShopDetailDto)getWXShopListDto(s, new WXShopDetailDto());
		dto.setAddress(s.getAddress());
		Page<WXCommentListDto>comments=commentService.getWXCommentListDtos(null,s.getId());
		dto.setComments(comments.getData());
		dto.setCommentCount(comments.getTotal());
		dto.setCoordinate(s.getCoordinate());
		dto.setDesc(s.getDesc());
		dto.setPhone(s.getLinkPhone());
		dto.setScheduleDesc("");
		Map<String, Object>param=Maps.newHashMap();
		param.put("sellerId", s.getId());
		param.put("orderByKey","-order,-ut");
		dto.setPros(proService.list(param).stream().map(p->{
			return proManager.getWXProListDto(p);
		}).collect(Collectors.toList()));
		return dto;
	}
}
